import { tableSelectButtonClass } from '@/enums/baseConstant';

// 格式化日期时间
const formatDateTime = (row: any, column: any, cellValue: string) => {
	if (!cellValue) return '';
	// 处理日期格式，将 2025-04-16T10:47:38.3636223 转换为 2025-04-16 10:47:38
	const date = new Date(cellValue);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	const seconds = String(date.getSeconds()).padStart(2, '0');
	return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};

// 根据难度级别格式化显示
const formatLevel = (row: any, column: any, cellValue: number) => {
	if (cellValue === undefined || cellValue === null) return '未设置';
	const levelMap: Record<number, string> = {
		1: '基础',
		2: '简单',
		3: '一般',
		4: '困难',
		5: '进阶',
	};
	return levelMap[cellValue] || `级别 ${cellValue}`;
};

// 格式化所属课程
const formatCourse = (row: any) => {
	if (row.courseNode && row.courseNode.name) {
		return row.courseNode.name;
	}
	return '未分配';
};

export const columns = [
	{
		label: '#',
		type: 'selection',
		fixed: 'left',
		selectable: (row: any) => !row.lockDelete,
	},
	{
		label: '序号',
		type: 'index',
		index: (index: number) => index + 1,
		width: 60,
	},
	{
		label: '知识点名称',
		prop: 'name',
		minWidth: 140,
	},
	{
		label: '知识点概述',
		prop: 'summary',
		minWidth: 180,
	},
	{
		label: '难度级别',
		prop: 'level',
		minWidth: 100,
		slot: 'level',
	},
	{
		label: '所属课程',
		prop: 'courseNode.name',
		minWidth: 140,
		formatter: formatCourse,
	},
	{
		label: '标签',
		prop: 'tags',
		minWidth: 230,
		slot: 'tags',
	},
	{
		label: '创建时间',
		prop: 'createTime',
		sortable: true,
		minWidth: 160,
		formatter: formatDateTime,
	},
	{
		label: '更新时间',
		prop: 'updateTime',
		sortable: true,
		minWidth: 160,
		formatter: formatDateTime,
	},
	{
		label: '创建人',
		prop: 'createdByUsername',
		minWidth: 120,
		slot: 'createUser',
	},
	{
		label: '更新人',
		prop: 'updatedByUsername',
		minWidth: 120,
		slot: 'updateUser',
	},
	{
		label: '操作',
		fixed: 'right',
		width: 260,
		slot: 'operation',
	},
];
